package org.example;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.operators.Order;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.*;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.util.Collector;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class demo {
    public static void main(String[] args) throws Exception {
        List<Tuple2> list = new ArrayList<>();
        list.add(new Tuple2("a1", 50.2));
        list.add(new Tuple2("a2", 13.6));
        list.add(new Tuple2("a3", 60.3));
        ExecutionEnvironment executionEnvironment = ExecutionEnvironment.getExecutionEnvironment();
        DataSource<Tuple2> tuple2DataSource = executionEnvironment.fromCollection(list);
        SortPartitionOperator<Tuple2> tuple2SortPartitionOperator = tuple2DataSource.sortPartition(1, Order.DESCENDING);
        GroupReduceOperator<Tuple2, Tuple2> first = tuple2SortPartitionOperator.first(1);
        List<Tuple2> collect = first.collect();
        System.out.println("collectSize "+collect.size());

        for (Tuple2 tuple2 : collect) {
            System.out.println("hhhhhhhhh" + tuple2.f0 + " "+tuple2.f1);
        }

    }
}
